﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.IdentityModel.Tokens;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyExtension.Authorizations
{
    /// <summary>
    /// 必要参数类
    /// 继承 IAuthorizationRequirement,用于设计自定义权限处理器 PermissionHandler
    /// 因为 AuthorizationHandler 中的泛型参数 TRequirement 必须继承 IAuthorizationRequirement
    /// </summary>
    public class PermissionRequirement:IAuthorizationRequirement
    {
        /// <summary>
        /// 用户权限集合，就像一个订单包含很多详情
        /// 同理，一个网站认证发行中，也有很多权限详情（这里是Role和URL关系）
        /// </summary>
        public List<PermissionItem> Permissions { get; set; }

        /// <summary>
        /// 无权限 Action
        /// </summary>
        public string DeniedAction { get; set; }

        /// <summary>
        /// 认证授权类型
        /// </summary>
        public string ClaimType { get; set; }

        /// <summary>
        /// 登录地址
        /// </summary>
        public string LoginPath { get; set; } = "/Api/Login";

        /// <summary>
        /// 发行人
        /// </summary>
        public string Issure { get; set; }

        /// <summary>
        /// 订阅人
        /// </summary>
        public string Audience { get; set; }

        /// <summary>
        /// 过期时间
        /// </summary>
        public TimeSpan Expiration { get; set; }

        /// <summary>
        /// 签名验证
        /// </summary>
        public SigningCredentials SigningCredentials { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="deninedAction"></param>
        /// <param name="permissions"></param>
        /// <param name="claimType"></param>
        /// <param name="issure"></param>
        /// <param name="audience"></param>
        /// <param name="signingCredentials"></param>
        /// <param name="expiration"></param>
        public PermissionRequirement(string deninedAction,List<PermissionItem> permissions,string claimType,string issure,string audience,SigningCredentials signingCredentials,TimeSpan expiration)
        {
            Permissions = permissions;
            DeniedAction = deninedAction;
            ClaimType = claimType;
            Issure = issure;
            Audience = audience;
            Expiration = expiration;
            SigningCredentials = signingCredentials;
        }
    }
}
